package com.gt.web.srv.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * 积分交易类型枚举
 *
 * @author Yu Chaohua
 * @date 2024/5/24 0:46
 */
@Getter
@AllArgsConstructor
public enum TradeTypeEnum {

    ARTICLE_READ_REWARD(1, "文章阅读奖励", 1),
    ARTICLE_COMMENT_REWARD(2, "文章评论奖励", 1),
    ARTICLE_COLLECTION_REWARD(3, "文章收藏奖励", 1),
    OTHER_REWARD(4, "其他奖励", 1),
    PRODUCT_EXCHANGE(5, "商品兑换", 2),
    PRODUCT_REFUND(6, "商品退还", 1),
    SYSTEM_ADD(7, "系统调加", 1),
    SYSTEM_REDUCE(8, "系统调减", 2),
    VOUCHER_EXCHANGE(9, "兑换券", 2),
    ACTIVITY_ADD(10, "参与活动", 1),
    REWARD_ADD(11, "分享荣誉", 1),
    ;

    private Integer code;

    private String desc;

    /**
     * 1收入 2支出
     */
    private int addOrSub;

    private static final Map<Integer, TradeTypeEnum> CODE_MAP = new HashMap<>((int) (values().length / .75f) + 1);

    static {
        for (TradeTypeEnum item : values()) {
            CODE_MAP.put(item.code, item);
        }
    }

    public static TradeTypeEnum fromCode(Integer code) {
        return CODE_MAP.get(code);
    }
}
